package com.cty.servlet.servlet6;

import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @Auther: cty
 * @Date: 2020/2/12 16:32
 * @Description:
 * @version: 1.0
 */
@WebServlet(name = "ServletContextServlet2")
public class ServletContextServlet2 extends HttpServlet {
    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp)
            throws ServletException, IOException {
        //创建ServletContext对象
        ServletContext sc=this.getServletContext();
        //获取数据
        System.out.println("ServletContextServlet2.service()"+sc.getAttribute("str"));
    }
}
